function varposterior = computeBayesGaussianVerbeek(varprior, data, w, covar_type, reg)


D = size(data.Y, 2);

m0 = varprior.m0;
b0 = varprior.b0;
W0 = varprior.W0;
v0 = varprior.v0;

[sample_mean sample_sigma] = computeMLEGaussianVerbeek(data, w, covar_type, reg);

b = b0 + sum(w);
m = (b0*m0 + sum(w)*sample_mean)/b;
inv_W = inv(W0) + sum(w)*sample_sigma + (sample_mean - m0)'*(sample_mean -m0)*b0*sum(w)/(b0+sum(w));
switch covar_type
    case 'full'

    case 'diagonal'
        inv_W = diag(diag(inv_W));
    case 'spherical'
        inv_W = eye(D)*mean(diag(inv_W));
    otherwise
        error(['Unknown covariance type ', covar_type]);
end
W = inv(inv_W);
v = v0 + sum(w);

varposterior.m = m;
varposterior.b = b;
varposterior.W = W;
varposterior.v = v;
